package com.hh.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hh.erp.entity.SysConfig;
import com.hh.erp.mapper.SysConfigMapper;
import com.hh.erp.service.SysConfigService;
import com.hh.erp.util.StringUtil;
import com.hh.erp.util.http.AjaxResult;
import com.hh.erp.util.http.DiscoveryException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 参数配置表 服务实现类
 * </p>
 *
 * @author zhb
 * @since 2024-04-15
 */
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    /**
     * 系统默认应该加载全局配置
     * @return
     */
    @Override
    public List<SysConfig> getConfigList() {
        List<SysConfig> list = this.baseMapper.selectList(new QueryWrapper<SysConfig>());
        return list;
    }

    @Override
    public SysConfig getConfigValue(String configKey) {

        if (StringUtil.IsSpace(configKey)) {
            throw new DiscoveryException("configKey参数不能为空！");
        }

        SysConfig config = this.baseMapper.selectOne(
                new QueryWrapper<SysConfig>()
                .select(SysConfig.CONFIG_VALUE)
                .eq(SysConfig.CONFIG_KEY,configKey)
        );

        if(config == null) {
            throw new DiscoveryException( "没有找到对应的参数配置信息！");
        }
        return config;
    }


}
